package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CSearch
import com.onlyphoto.onlymall.mvp.model.MSearchImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.request.GoodsCondition
import com.onlyphoto.onlymall.bean.response.GoodsBean


class PSearchImpl(mContext: Context, mView: CSearch.IVSearch) : BasePresenter<CSearch.IVSearch, MSearchImpl>(mContext, mView, MSearchImpl()), CSearch.IPSearch {
    override fun getTopSearch() {
        mModel.requestTopSearch(object :BaseObserver<ArrayList<String>>(mContext.get()){
            override fun onSuccess(data: ArrayList<String>?, msg: String?) {
                mView.getTopSearchSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<String>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun search(condition: GoodsCondition) {
        mModel.requestGoods(condition, object :BaseObserver<ArrayList<GoodsBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<GoodsBean>?, msg: String?) {
                mView.searchSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<GoodsBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
